package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.SetMealService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SetMealVO;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/set/meal")
public class SetMealController extends BaseController{

	@Autowired
	private SetMealService setMealService;
	
	@ApiOperation(value="获取所有套餐列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,SetMealVO setMealVO){
		return setMealService.findAll(dtp,setMealVO);
	}
	
	@ApiOperation(value="新增套餐")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(SetMealVO setMealVO){
		ResultVO result = new ResultVO();
		result.setData(setMealService.add(setMealVO));
		return result;
	}
	
	@ApiOperation(value="删除套餐")
	@RequestMapping(value="/{id}" , method = RequestMethod.DELETE)
	public ResultVO delete(@PathVariable String id){
		ResultVO result = new ResultVO();
		AssertUtil.notBlank(id, "id is required.");
		result.setData(setMealService.delete(id));
		return result;
	}
	
	@ApiOperation(value="根据ID查询套餐详情")
	@RequestMapping(value="/info/{id}" ,method = RequestMethod.GET)
	public ResultVO getSetMealById(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required.");
		return setMealService.getSetMealById(id);
	}


	@ApiOperation(value="修改套餐详情")
	@RequestMapping(value="/update" ,method = RequestMethod.PUT)
	public ResultVO update(SetMealVO setMealVO){
		AssertUtil.notBlank(setMealVO.getId(), "setMealId is required.");
		return setMealService.update(setMealVO);
	}
	
	@ApiOperation(value="查询套餐详情")
	@RequestMapping(value="/list" ,method = RequestMethod.GET)
	public ResultVO getSetMealList(SetMealVO setMealVO){
		AssertUtil.notNull(setMealVO.getType(), "type is required");
		return setMealService.getSetMealList(setMealVO);
	}
	
	@ApiOperation(value="查询套餐简练信息")
	@RequestMapping(value="/concise" ,method = RequestMethod.GET)
	public ResultVO findAllConcise(SetMealVO setMealVO){
		return setMealService.findAllConcise(setMealVO);
	}
	
	@ApiOperation(value="获取套餐名称(下拉框)")
	@RequestMapping(value="/list/name",method=RequestMethod.GET)
	public ResultVO getSetMealName(SetMealVO smv){
		return setMealService.getSetMealList(smv);
	}
}
